angular.module('xqing',[])
.config(['$routeProvider',function($routeProvider){
	$routeProvider 
	.when('/xqing',{
		templateUrl:'html/xqing/xqing.html',
		css:'html/xqing/xqing.css'
	})
}])
.controller('xqingCtrl',function($scope,$rootScope){
	//头部和底部显示隐藏
	$rootScope.sh = true;

	//加
	$rootScope.gwc = [];
	$scope.add = function(obj){
		return obj['num']++;
	}
	//减
	$scope.remove = function(obj){
		return obj['num']--;
	}
	
	//详情页数据
	$scope.xqy = JSON.parse(localStorage.arrr);
	//加入购物车按钮
	$scope.join = function(obj){
		//判断是否登录
		if(localStorage.sb){
			for(var i=0;i<$rootScope.gwc.length;i++){
				if($rootScope.gwc[i]['name'] == obj['name']){
					alert("购物车已经有此商品!");
					return;
				}
			}
			$rootScope.gwc.push(obj);
			var nn1 = $('.xq_p2 img').attr('src');
			var nn2=document.getElementsByClassName("xq_div1_p1")[0].innerHTML;
			var nn3=document.getElementsByClassName("ja")[0].innerHTML;
			var nn4=document.getElementsByClassName("shuz")[0].innerHTML;
		 	var ajax= new XMLHttpRequest();
			ajax.open('POST','http://www.yanhanbo.top/user/gouwuche.php');
			ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			ajax.send('img='+nn1+'&name='+nn2+'&price='+nn3+'&num='+nn4);
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState == 4){
					console.log('添加成功');
					location.reload();
				}
			}
		}else{
			alert('您尚未登录!请先登录在进行购买!');
	 		window.location.href="http://127.0.0.1:8020/pcduantao/Taocz%20PC/src/index.html#/login";
		}
	}
	document.body.scrollTop = 0;
//	console.log()
	
	$(".yy_p1 span").click(function(){
		$(this).css({
			background:'#fff'
		}).siblings().css({
			background:'#f7f7f7'
		})
	})
	$(".p1_sp1").click(function(){
		$(".yy_p2").show()
		$(".yy_p3").show()
		$(".yy_p4").show()
		$(".yy_p5").show()
	})
	$(".p1_sp2").click(function(){
		$(".yy_p2").hide()
		$(".yy_p5").hide()
		$(".yy_p3").show()
		$(".yy_p4").show()
	})
	$(".p1_sp3").click(function(){
		$(".yy_p3").hide()
		$(".yy_p4").hide()
		$(".yy_p5").show()
	})
})
